package com.lry.web.listener;

import com.lry.web.config.RabbitMQConfig;
import com.rabbitmq.client.Channel;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.util.HashSet;

@Component
public class SurviceListener {

    public static HashSet<String> uuidSet = new HashSet<String>();
    public static HashSet<String> uuidSetTTL = new HashSet<String>();
    //监听survice_queue队列
    @RabbitListener(queues = RabbitMQConfig.SURVIVEQUEUE_NAME)
    public void ListenerSurviceQueue(Message message, Channel channel) throws Exception {
        uuidSetTTL.add(new String(message.getBody()));
    }

    @Scheduled(cron = "5/21 * * * * ?")
    public void Survice(){
        uuidSet.clear();
        for(String uuid: uuidSetTTL){
            uuidSet.add(uuid);
        }
        uuidSetTTL.clear();
    }
}

